package com.mall.web.control.eshop;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.mall.biz.ImageUploadBizImpl;
import com.mall.biz.eshop.EshopBizImpl;
import com.mall.biz.eshop.EshopTouchBizImpl;
import com.mall.biz.eshop.EshopTradeBizImpl;
import com.mall.biz.eshop.TransferAuditBizImpl;
import com.mall.biz.trade.TradeBizImpl;
import com.mall.biz.user.record.CollectionBizImpl;
import com.mall.client.eshop.EshopCompanyService;
import com.mall.client.eshop.EshopService;
import com.mall.client.eshop.EshopTouchService;
import com.mall.client.eshop.EshopTradeService;
import com.mall.client.eshop.EshopTrademarkService;
import com.mall.client.eshop.EshopUserInfoService;
import com.mall.client.eshop.SaleEshopService;
import com.mall.client.eshop.TransferAuditService;
import com.mall.client.search.EShopLuceneBuildService;
import com.mall.client.trade.TradeService;
import com.mall.client.user.CollectionService;
import com.mall.client.user.UserExtendedService;
import com.mall.client.user.UserService;
import com.mall.common.util.PageUtil;
import com.mall.common.util.bit.PropertiesConfigure;
import com.mall.constant.PropertiesKey;
import com.mall.constant.UserConstant;
import com.mall.enums.CollectionEnum;
import com.mall.enums.EshopUserInfoEnum;
import com.mall.pojo.Collection;
import com.mall.pojo.CollectionExample;
import com.mall.pojo.Eshop;
import com.mall.pojo.EshopCompany;
import com.mall.pojo.EshopTouch;
import com.mall.pojo.EshopTouchExample;
import com.mall.pojo.EshopTrade;
import com.mall.pojo.EshopTrademark;
import com.mall.pojo.EshopUserInfo;
import com.mall.pojo.SaleEshop;
import com.mall.pojo.Trade;
import com.mall.pojo.TradeExample;
import com.mall.pojo.TransferAudit;
import com.mall.pojo.User;
import com.mall.pojo.UserExtended;
import com.mall.query.Page;
import com.mall.query.TradeRecordQuery;
import com.mall.query.collection.CollectionQuery;
import com.mall.query.eshop.EshopQuery;
import com.mall.query.eshop.EshopTouchQuery;
import com.mall.query.eshop.EshopUserQuery;
import com.mall.query.eshop.SaleEshopQuery;
import com.mall.query.eshop.TransferAuditQuery;
import com.mall.vo.eshop.CollectionVO;
import com.mall.vo.eshop.SaleEshopQO;
import com.mall.vo.eshop.SaleEshopVO;
import com.mall.vo.eshop.TransferAuditVO;
import com.mall.vo.trade.TradeVO;
import com.mall.web.annotation.AdminSecurity;
import com.mall.web.annotation.EShopUserSecurity;
import com.mall.web.util.HttpUtil;
import com.mall.web.util.MoneyUtil;
import com.mall.web.util.PinYinUtil;
import com.mall.web.util.QRCodeUtil;
import com.mall.web.util.StringUtil;
import com.mall.web.util.WebUtil;
import com.mall.web.vo.ResponseEntity;

@Controller
@RequestMapping("/eshop/backEshop/")
/**
 * pc端运营后台操作
 * @author Administrator
 *
 */
public class EshopBackController {
	
	@Autowired
	private EshopUserInfoService eshopUserInfoService;
	@Autowired
	private EshopService eshopService;
	@Autowired
	private SaleEshopService saleEshopService;
	@Autowired
	private EshopCompanyService eshopCompanyService;
	@Autowired
	private EshopTrademarkService eshopTrademarkService;
	@Autowired
	private EShopLuceneBuildService eShopLuceneBuildService;
	@Autowired
	private CollectionBizImpl collectionBizImpl;
	@Autowired
	private ImageUploadBizImpl imageUploadBizImpl;
	@Autowired
	private PropertiesConfigure propertiesConfigure;
	@Autowired
	private UserExtendedService userExtendedService;
	@Autowired
	private EshopTouchService eshopTouchService;
	@Autowired
	private EshopBizImpl eshopBizImpl;
	@Autowired
	private EshopTouchBizImpl eshopTouchBizImpl;
	@Autowired
	private CollectionService collectionService;
	@Autowired
	private UserService userService;
	@Autowired
	private TransferAuditBizImpl transferAuditBizImpl;
	@Autowired
	private TransferAuditService transferAuditService;
	@Autowired
	private EshopTradeBizImpl eshopTradeBizImpl;
	@Autowired
	private TradeBizImpl tradeBizImpl;
	@Autowired
	private TradeService tradeService;
	@Autowired
	private EshopTradeService eshopTradeService;
	
	
	// 图片保存的文件夹名字
	private final String folder = "eshop";
	// erweima图片保存的文件夹名字
	private final String erweimaFolder = "erweima";
	
	@RequestMapping("backManage")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backManage(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		User user = WebUtil.getCurrentUser(request);
		modelMap.put("user", user);
		return "eshop/back/backManage";
	}
	
	
	/**
	 * 功能一：代理商首页
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("agentList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String agentList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap,EshopUserInfo eshopUserInfo) {
		User user = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		
		String name = HttpUtil.getStringValueFromRequest(request, "name");
		Long qq = HttpUtil.getLongValueFromRequest(request, "qq");
		String phone = HttpUtil.getStringValueFromRequest(request, "phone");
		String wangwang = HttpUtil.getStringValueFromRequest(request, "wangwang");
		
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		EshopUserQuery eshopUserQuery = new EshopUserQuery();
		eshopUserQuery.setPage(page);
		eshopUserQuery.setOnlyKey(onlyKey);
		eshopUserQuery.setType(EshopUserInfoEnum.AGENT.getCode());
		if(StringUtils.isNotBlank(name)){
			eshopUserQuery.setName(name);
		}
		if(qq != null){
			eshopUserQuery.setQq(qq);
		}
		if(StringUtils.isNotBlank(phone)){
			eshopUserQuery.setPhone(phone);
		}
		if(StringUtils.isNotBlank(wangwang)){
			eshopUserQuery.setWangwang(wangwang);
		}
		eshopUserQuery.setOrderby("id desc");
		int size = this.eshopUserInfoService.getEshopUserInfoCountByQuery(eshopUserQuery);
		List<EshopUserInfo> agentInfoList = this.eshopUserInfoService.getEshopUserInfoListBySellerInfoByQuery(eshopUserQuery, page);
		
		
		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("agentInfoList", agentInfoList);
		modelMap.put("user", user);
		return "eshop/back/agentList";
	}
	
	
	/**
	 * 新增代理商
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("addAgent")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String addAgent(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap,EshopUserInfo eshopUserInfo) {
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		eshopUserInfo.setCommOnlyKey(onlyKey);
		this.eshopUserInfoService.insertEshopUserInfoBySellerInfo(eshopUserInfo);
		String referer = HttpUtil.getHttpReferer(request);
		return "redirect:"+referer;
	}
	
	
	/**
	 * 编辑代理商
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("editAgent")
	@ResponseBody
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<String> editAgent(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		Long agentId = HttpUtil.getLongValueFromRequest(request, "agentId");
		EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(agentId);
		if(eshopUserInfo == null){
			responseEntity.initErrorResponseEntity(null, "用户不存在");
		}
		String name = HttpUtil.getStringValueFromRequest(request, "name");
		String phone = HttpUtil.getStringValueFromRequest(request, "phone");
		Long qq = HttpUtil.getLongValueFromRequest(request, "qq");
		String weixin = HttpUtil.getStringValueFromRequest(request, "weixin");
		eshopUserInfo.setName(name);
		eshopUserInfo.setPhone(phone);
		eshopUserInfo.setQq(qq);
		eshopUserInfo.setWangwang(weixin);
		this.eshopUserInfoService.modifyEshopUserInfoBySellerInfo(eshopUserInfo);
		responseEntity.initSuccResponseEntity(null, "修改成功");
		return responseEntity;
	}
	
	/**
	 * 删除代理商
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("deleteAgent")
	@ResponseBody
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<String> deleteAgent(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		Long agentId = HttpUtil.getLongValueFromRequest(request, "agentId");
		EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(agentId);
		if(eshopUserInfo == null){
			responseEntity.initErrorResponseEntity(null, "用户不存在");
		}
		
		eshopUserInfo.setType(999);
		this.eshopUserInfoService.modifyEshopUserInfoBySellerInfo(eshopUserInfo);
		responseEntity.initSuccResponseEntity(null, "修改成功");
		return responseEntity;
	}
	
	/**
	 * 查看属于该代理商下的店铺
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("agentEshopList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String agentEshopList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		User user = WebUtil.getCurrentUser(request);
		Long agentId = HttpUtil.getLongValueFromRequest(request, "agentId");
		EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(agentId);
		if(eshopUserInfo == null){
			return null;
		}
		//设置分页
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		
		EshopQuery eshopQuery = new EshopQuery();
		eshopQuery.setEshopSellerId(agentId);
		int size = this.eshopBizImpl.getEshopCountByQuery(eshopQuery);
		eshopQuery.setPage(page);
		List<Eshop> eshopList = this.eshopBizImpl.getEshopListByEshopQuery(eshopQuery);
		List<SaleEshopVO> saleEshopVOList = this.eshopBizImpl.getSaleEshopVOListByEshopList(eshopList);
		
		//按类目排序
		//Collections.sort(saleEshopVOList);  
		
		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("saleEshopVOList", saleEshopVOList);
		modelMap.put("eshopUserInfo", eshopUserInfo);
		modelMap.put("user", user);
		return "eshop/back/agentEshopList";
	}
	
	@RequestMapping("editEshop")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String editEshop(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		String referer = HttpUtil.getHttpReferer(request);
		User currentUser = WebUtil.getCurrentUser(request);
		String eshopId = request.getParameter("eshopId");
		Long eshopUserId = HttpUtil.getLongValueFromRequest(request, "eshopUserId");
		int isModifyEshop = 0;
		Eshop eshop = null;
		SaleEshop saleEshop = null;
		EshopCompany eshopCompany = null;
		EshopTrademark eshopTrademark = null;
		if (StringUtils.isNotBlank(eshopId)) {
			eshop = this.eshopService.getEshopByEshopId(Long.parseLong(eshopId));
			if (eshop == null) {
				return null;
			}
			saleEshop = this.saleEshopService.getSaleEshopBySaleEshopId(eshop.getSaleEshopId());
			eshopCompany = this.eshopCompanyService.getEshopCompanyByEshopCompanyId(eshop.getEshopCompanyId());
			eshopTrademark = this.eshopTrademarkService.getEshopTrademarkByEshopTrademarkId(eshop.getTrademarkId());
			isModifyEshop = 1;
		}
		modelMap.put("eshopUserId", eshopUserId);
		modelMap.put("eshop", eshop);
		modelMap.put("saleEshop", saleEshop);
		modelMap.put("eshopCompany", eshopCompany);
		modelMap.put("eshopTrademark", eshopTrademark);
		modelMap.put("isModifyEshop", isModifyEshop);
		modelMap.put("currentUser", currentUser);
		modelMap.put("user", currentUser);
		modelMap.put("referer", referer);
		return "eshop/back/editEshop";
	}
	
	/**
	 * 修改代理商下的店铺状态：0在售  1已售 -1取消
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("modifySaleEshopStatus")
	@ResponseBody
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<String> modifySaleEshopStatus(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		
		Long saleEshopId = HttpUtil.getLongValueFromRequest(request, "saleEshopId");
		SaleEshop saleEshop = this.saleEshopService.getSaleEshopBySaleEshopId(saleEshopId);
		if(saleEshop == null){
			responseEntity.initErrorResponseEntity(null, "店铺不存在");
		}
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");	
		saleEshop.setStatus(status);
		this.saleEshopService.modifySaleEshopBySaleEshop(saleEshop, null);
		responseEntity.initSuccResponseEntity(null, "修改成功");
		return responseEntity;
	}
	
	
	/**
	 * 根据店铺名检测是否已经录入
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("checkEshopName")   
	@ResponseBody
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<String> checkEshopName(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		
		String eshopName = HttpUtil.getStringValueFromRequest(request, "eshopName");
		if(StringUtils.isBlank(eshopName)){
			responseEntity.setCode("-300");
			responseEntity.setData(null);
			responseEntity.setMessage("请输入店铺名");
			return responseEntity;
		}
		Eshop eshop = this.eshopService.getEshopByEshopName(eshopName);
		if(eshop == null){
			responseEntity.initSuccResponseEntity(null, "店铺名可用");
			return responseEntity;
		}
		responseEntity.initErrorResponseEntity(null, "店铺已录入");
		return responseEntity;
	}
	
	
	
	/**
	 * 新增店铺
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("editEshopAction")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	@Transactional
	public String editEshopAction(@RequestParam("turnoverImgFile") MultipartFile turnoverImgFile,
			@RequestParam("categoryImgFile") MultipartFile categoryImgFile,
			@RequestParam("secCategoryImgFile") MultipartFile secCategoryImgFile,
			@RequestParam("koufenImgFile") MultipartFile koufenImgFile, HttpServletRequest request,
			HttpServletResponse response, ModelMap modelMap, SaleEshopQO saleEshopQO) {
		String referer = HttpUtil.getStringValueFromRequest(request, "referer");
		Long eshopId = HttpUtil.getLongValueFromRequest(request, "eshopId");
		Eshop currentEshop = this.eshopService.getEshopByEshopId(eshopId);
		User currentUser = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Long eshopUserId = HttpUtil.getLongValueFromRequest(request, "eshopUserId");
		Integer isModifyEshop = HttpUtil.getIntegerValueFromRequest(request, "isModifyEshop");

		Eshop eshop = saleEshopQO.getEshop();
		SaleEshop saleEshop = saleEshopQO.getSaleEshop();
		EshopCompany eshopCompany = saleEshopQO.getEshopCompany();
		EshopTrademark eshopTrademark = saleEshopQO.getEshopTrademark();

		// 插入公司表
		eshopCompany.setGmtModify(new Date());
		eshopCompany.setCommOnlyKey(onlyKey);
		eshopCompany.setType(0);
		eshopCompany.setStatus(0);
		if (isModifyEshop == 0) {
			eshopCompany.setCreateUserId(currentUser.getId());
			eshopCompany.setGmtCreate(new Date());
			this.eshopCompanyService.insertEshopCompanyByEshopCompany(eshopCompany);

		} else if (isModifyEshop == 1 && currentEshop != null) {
			EshopCompany existEshopCompany = this.eshopCompanyService
					.getEshopCompanyByEshopCompanyId(currentEshop.getEshopCompanyId());
			eshopCompany.setCreateUserId(currentUser.getId());
			this.eshopCompanyService.modifyEshopCompanyByEshopCompany(eshopCompany, existEshopCompany);
		}

		// 插入商标表
		eshopTrademark.setGmtModify(new Date());
		eshopTrademark.setCommOnlyKey(onlyKey);
		eshopTrademark.setStatus(0);
		eshopTrademark.setType(0);
		if (isModifyEshop == 0) {
			eshopTrademark.setGmtCreate(new Date());
			eshopTrademark.setCreateUserId(currentUser.getId());
			this.eshopTrademarkService.insertEshopTrademarkByEshopTrademark(eshopTrademark);
		} else if (isModifyEshop == 1 && currentEshop != null) {
			EshopTrademark existEshopTrademark = this.eshopTrademarkService
					.getEshopTrademarkByEshopTrademarkId(currentEshop.getTrademarkId());
			eshopTrademark.setCreateUserId(currentUser.getId());
			this.eshopTrademarkService.modifyEshopTrademarkByEshopTrademark(eshopTrademark, existEshopTrademark);
		}

		// 插入saleEshop
		// 图片
		
		if (turnoverImgFile != null && !turnoverImgFile.getOriginalFilename().equals("")) {
			String turnoverImg = imageUploadBizImpl.uploadImage(turnoverImgFile, folder, request);
			if (StringUtils.isNotBlank(turnoverImg)) {
				saleEshop.setTurnoverImg(turnoverImg);
			}
		}

		if (categoryImgFile != null  && !categoryImgFile.getOriginalFilename().equals("")) {
			String categoryImg = imageUploadBizImpl.uploadImage(categoryImgFile, folder, request);
			if (StringUtils.isNotBlank(categoryImg)) {
				saleEshop.setCategoryImg(categoryImg);
			}
		}

		if (secCategoryImgFile != null  && !secCategoryImgFile.getOriginalFilename().equals("")) {
			String secCategoryImg = imageUploadBizImpl.uploadImage(secCategoryImgFile, folder, request);
			if (StringUtils.isNotBlank(secCategoryImg)) {
				saleEshop.setSecCategoryImg(secCategoryImg);
			}
		}

		if (koufenImgFile != null  && !koufenImgFile.getOriginalFilename().equals("")) {
			String koufenImg = imageUploadBizImpl.uploadImage(koufenImgFile, folder, request);
			if (StringUtils.isNotBlank(koufenImg)) {
				saleEshop.setKoufenImg(koufenImg);
			}
		}

		String pyName = PinYinUtil.getPinYinFromChinese(saleEshop.getProvinceName()) + saleEshop.getProvinceName()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getCityName()) + saleEshop.getCityName()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getAreaName()) + saleEshop.getAreaName()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getChinaArea()) + saleEshop.getChinaArea()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getEshopFeature()) + saleEshop.getEshopFeature()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getSellerMessage()) + saleEshop.getSellerMessage()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getMainGoods()) + saleEshop.getMainGoods()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getCategoryName()) + saleEshop.getCategoryName()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getTitle()) + saleEshop.getTitle()
				+ PinYinUtil.getPinYinFromChinese(saleEshop.getSecCategoryName()) + saleEshop.getSecCategoryName();
		saleEshop.setPyName(pyName);
		saleEshop.setTaxpayerType(eshopCompany.getTaxpayerQualification());
		saleEshop.setTrademarkType(eshopTrademark.getTrademarkType());
		saleEshop.setGmtModify(new Date());
		saleEshop.setShowPrice(saleEshop.getShowPrice());
		saleEshop.setPrice(MoneyUtil.getEshopPrice(saleEshop.getShowPrice()));
		saleEshop.setTrademarkType(eshopTrademark.getTrademarkType());
		saleEshop.setTaxpayerType(eshopCompany.getTaxpayerQualification());
		saleEshop.setCommOnlyKey(onlyKey);
		saleEshop.setType(0);
		saleEshop.setStatus(0);
		String eshopSearchDir = propertiesConfigure.getProperties(PropertiesKey.eshopsearchdir);
		if (isModifyEshop == 0) {
			saleEshop.setEshopCompanyId(eshopCompany.getId());
			saleEshop.setTrademarkId(eshopTrademark.getId());
			saleEshop.setEshopNo(this.saleEshopService.generateEshopNo());
			saleEshop.setPyName(pyName + saleEshop.getEshopNo());
			saleEshop.setGmtCreate(new Date());
			this.saleEshopService.insertSaleEshopBySaleEshop(saleEshop);
			eshopCompany.setSaleEshopId(saleEshop.getId());
			this.eshopCompanyService.modifyEshopCompanyByKey(eshopCompany);
			eshopTrademark.setSaleEshopId(saleEshop.getId());
			this.eshopTrademarkService.modifyEshopTrademarkByKey(eshopTrademark);
			List<SaleEshop> saleEshopList = new ArrayList<>();
			saleEshopList.add(saleEshop);
			this.eShopLuceneBuildService.buildAll(saleEshopList, eshopSearchDir);
		} else if (isModifyEshop == 1 && currentEshop != null) {
			SaleEshop existSaleEshop = this.saleEshopService.getSaleEshopBySaleEshopId(currentEshop.getSaleEshopId());
			this.saleEshopService.modifySaleEshopBySaleEshop(saleEshop, existSaleEshop);
			List<SaleEshop> saleEshopList = new ArrayList<>();
			saleEshopList.add(saleEshop);
			this.eShopLuceneBuildService.update(saleEshopList, eshopSearchDir);
		}

		// 插入eshop表
		eshop.setGmtModify(new Date());
		eshop.setCommOnlyKey(onlyKey);
		if (isModifyEshop == 0) {
			eshop.setGmtCreate(new Date());
			eshop.setEshopCompanyId(eshopCompany.getId());
			eshop.setSaleEshopId(saleEshop.getId());
			eshop.setTrademarkId(eshopTrademark.getId());
			eshop.setCreateUserId(currentUser.getId());
			eshop.setEshopSellerId(eshopUserId);
			this.eshopService.insertEshopByEshop(eshop);
			EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(eshopUserId);
			eshopUserInfo.setEshopId(eshop.getId());
			eshopUserInfo.setUserId(currentUser.getId());
			this.eshopUserInfoService.modifyEshopUserInfoBySellerInfo(eshopUserInfo);
		}
		if (isModifyEshop == 1 && currentEshop != null) {
			eshop.setCreateUserId(currentUser.getId());
			Eshop existEshop = this.eshopService.getEshopByEshopId(currentEshop.getId());
			this.eshopService.modifyEshopByEshop(eshop, existEshop);
		}
		
		
		return "redirect:"+referer;
	}
	
	
	/**
	 * 转账信息列表
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	
	@RequestMapping("backTransferRecordList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String transferRecordList(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		transferRecordModelMap(request,response,modelMap);
		return "eshop/back/backTransferRecordList";
	}
	
	/**
	 * 转账信息列表
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backTransferRecordMore")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String transferRecordListMore(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		transferRecordModelMap(request,response,modelMap);
		return "eshop/back/backTransferRecordMore";
	}
	
	private ModelMap transferRecordModelMap(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize",PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		User user = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		Integer type = HttpUtil.getIntegerValueFromRequest(request, "type");
		String phone = HttpUtil.getStringValueFromRequest(request, "phone");
		
		TransferAuditQuery transferAuditQuery = new TransferAuditQuery();
		transferAuditQuery.setOnlyKey(onlyKey);
		transferAuditQuery.setPhone(phone);
		transferAuditQuery.setStatus(status);
		transferAuditQuery.setType(type);
		int size = this.transferAuditBizImpl.getTransferAuditCountByQuery(transferAuditQuery);
		transferAuditQuery.setPage(page);
		List<TransferAudit> transferAuditList = this.transferAuditBizImpl.getTransferAuditListByQuery(transferAuditQuery);
		
		List<TransferAuditVO> transferAuditVOList = new ArrayList<TransferAuditVO>();
		if(transferAuditList != null && transferAuditList.size() > 0){
			for(TransferAudit transferAudit : transferAuditList){
				TransferAuditVO transferAuditVO = new TransferAuditVO();
				User auditUser = this.userService.getUserByUserId(transferAudit.getUserId());
				transferAuditVO.setTransferAudit(transferAudit);
				transferAuditVO.setUser(auditUser);
				transferAuditVOList.add(transferAuditVO);
			}
		}
		
		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("transferAuditVOList", transferAuditVOList);
		modelMap.put("user", user);
		return modelMap;
	}
	
	/**
	 * 删除垃圾转账记录
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("deleteTransferRecord")   
	@ResponseBody
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<String> deleteTransferRecord(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		Long transferAuditId = HttpUtil.getLongValueFromRequest(request, "transferAuditId");
		TransferAudit transferAudit = this.transferAuditService.getTransferAuditById(transferAuditId);
		if(transferAudit == null){
			responseEntity.initErrorResponseEntity(null, "不存在该记录");
		}
		transferAudit.setStatus(-1);
		this.transferAuditService.modifyTransferAudit(transferAudit);
		responseEntity.initSuccResponseEntity(null, "转账记录已删除！");
		return responseEntity;
	}

	
	
	/**
	 * 给用户充值余额
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("addBalanceAction")
	@ResponseBody
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<String> addBalanceAction(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		Long transferAuditId = HttpUtil.getLongValueFromRequest(request, "transferAuditId");
		TransferAudit transferAudit = this.transferAuditService.getTransferAuditById(transferAuditId);
		if(transferAudit == null){
			responseEntity.initErrorResponseEntity(null, "无法操作");
			return responseEntity;
		}
		//更新用户余额
		UserExtended userExtended = this.userExtendedService.getUserExtendByUserId(transferAudit.getUserId());
		Double price = Double.parseDouble(request.getParameter("money"));
		Long addBalance = price.longValue();
		if(userExtended == null){
			userExtended = new UserExtended();
			userExtended.setBalance(addBalance);
		}else{
			userExtended.setBalance(addBalance+userExtended.getBalance());
		}
		this.userExtendedService.updateExtendedByPrimaryKey(userExtended);
		responseEntity.initSuccResponseEntity(null, "修改成功");
		return responseEntity;
	}
	
	
	/**********************************************二维码功能********************************************************/
	/**
	 * 生成二维码
	 */
	@RequestMapping("doErweima")
	public String doErweima(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		return "eshop/doErweima";
	}
	
	/**
	 * 上传二维码logo
	 */
	@RequestMapping(value="uploadLogo",method=RequestMethod.POST)
	@ResponseBody  
	public void uploadLogo(@RequestParam("erweimaLogo") MultipartFile erweimaLogo,HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		String erweimaUrl = imageUploadBizImpl.uploadImage(erweimaLogo, erweimaFolder, request);
		responseEntity.initSuccResponseEntity(erweimaUrl, "success");
		HttpUtil.ajaxJsonpOutput("", responseEntity, response);
	}
	/**
	 * 生成二维码
	 */
	@RequestMapping("doErweimaAction")
	@ResponseBody  
	public ResponseEntity<String> doErweimaAction(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();

		String text = HttpUtil.getStringValueFromRequest(request, "text");
		String erweimaLogo = HttpUtil.getStringValueFromRequest(request, "erweimaLogo");
		if(StringUtils.isBlank(text)){
			responseEntity.initErrorResponseEntity(null, "fail");
			return responseEntity;
		}
		String imgUrl = "";
		 try {
			imgUrl = QRCodeUtil.encode(text, erweimaLogo, propertiesConfigure.getProperties(PropertiesKey.userfilepath)+ImageUploadBizImpl.HTTP_XIE+erweimaFolder, true);
		} catch (Exception e) {
			e.printStackTrace();
		} 
		responseEntity.initSuccResponseEntity(erweimaFolder+ImageUploadBizImpl.HTTP_XIE+imgUrl, "success");
		return responseEntity;
	}
	
	
	/**
	 * 下载二维码到本地
	 */
	@RequestMapping("downloadErweima")
	@ResponseBody  
	public ResponseEntity<String> downloadErweima(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		String imgHttpUrl = HttpUtil.getStringValueFromRequest(request, "imgHttpUrl");
		int start = imgHttpUrl.lastIndexOf("/");  
		if (start == -1 ) {  
			responseEntity.initErrorResponseEntity(null, "图片路径错误！");
			return responseEntity;
	    }
		String downloadImgName =  imgHttpUrl.substring(start + 1);
		try {
			download(imgHttpUrl, downloadImgName,"C:/Users/Administrator/Desktop");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return responseEntity;
	}
	
	public void download(String urlString, String filename,String savePath) throws Exception {  
        // 构造URL  
        URL url = new URL(urlString);  
        // 打开连接  
        URLConnection con = url.openConnection();  
        //设置请求超时为5s  
        con.setConnectTimeout(5*1000);  
        // 输入流  
        InputStream is = con.getInputStream();  
      
        // 1K的数据缓冲  
        byte[] bs = new byte[1024];  
        // 读取到的数据长度  
        int len;  
        // 输出的文件流  
       File sf=new File(savePath);  
       if(!sf.exists()){  
           sf.mkdirs();  
       }  
       OutputStream os = new FileOutputStream(sf.getPath()+"\\"+filename);  
        // 开始读取  
        while ((len = is.read(bs)) != -1) {  
          os.write(bs, 0, len);  
        }  
        // 完毕，关闭所有链接  
        os.close();  
        is.close();  
    }   
  
	
	
	
	
	
	
	
	
	
	
	/**
	 * 后台查看未付款的eshoptrade订单信息
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backEshopTradeList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backEshopTradeList(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		User user = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize",PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		
		List<EshopTrade> eshopTradeList = this.eshopTradeBizImpl.getEshopTradeListByUserIdAndOnlyKey(null, onlyKey, 0, null);
		
		List<TradeVO> tradeVOList = new ArrayList<TradeVO>();
		TradeVO tradeVO =null;
		if(eshopTradeList != null && eshopTradeList.size() > 0){
			for(EshopTrade eshopTrade : eshopTradeList){
				tradeVO = new TradeVO();
				tradeVO.setEshopTrade(eshopTrade);
				tradeVO.setUser(this.userService.getUserByUserId(eshopTrade.getBuyUserId()));
				tradeVO.setSaleEshop(this.saleEshopService.getSaleEshopBySaleEshopId(eshopTrade.getSaleEshopId()));
				tradeVO.setOrPrice(eshopTrade.getPrice()+eshopTrade.getJishuPrice()+eshopTrade.getShouxuPrice()+eshopTrade.getXiaobaoPrice());
				tradeVOList.add(tradeVO);
			}
		}
		
		
		/*int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE_ESHOPLIST);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);*/
		modelMap.put("tradeVOList", tradeVOList);
		modelMap.put("user", user);
		return "eshop/back/backEshopTradeList";
	}  
	
	/**
	 * 后台查看trade订单信息
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backTradeList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backTradeList(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		User user = WebUtil.getCurrentUser(request);
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize",PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		
		TradeRecordQuery tradeRecordQuery = new TradeRecordQuery();
		tradeRecordQuery.setOnlyKey(onlyKey);
		tradeRecordQuery.setStatus(status);
		tradeRecordQuery.setOrderby("id desc");
		TradeExample tradeExample = this.tradeBizImpl.getTradeExampleByQuery(tradeRecordQuery);
		int size = this.tradeService.getTradeCount(tradeExample);
		tradeRecordQuery.setPage(page);
		tradeExample = this.tradeBizImpl.getTradeExampleByQuery(tradeRecordQuery);
		List<Trade> tradeList = this.tradeService.getTradeMessListByExample(tradeExample);
		
		List<TradeVO> tradeVOList = new ArrayList<TradeVO>();
		TradeVO tradeVO =null;
		if(tradeList != null && tradeList.size() > 0){
			for(Trade trade : tradeList){
				tradeVO = new TradeVO();
				EshopTrade eshopTrade = this.eshopTradeService.getEshopTradeByEshopTradeId(trade.getParentId());
				tradeVO.setTrade(trade);
				tradeVO.setUser(this.userService.getUserByUserId(eshopTrade.getBuyUserId()));
				tradeVO.setEshopTrade(eshopTrade);
				tradeVO.setSaleEshop(this.saleEshopService.getSaleEshopBySaleEshopId(eshopTrade.getSaleEshopId()));
				tradeVO.setOrPrice(eshopTrade.getPrice()+eshopTrade.getJishuPrice()+eshopTrade.getShouxuPrice()+eshopTrade.getXiaobaoPrice());
				tradeVOList.add(tradeVO);
			}
		}
		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("tradeVOList", tradeVOList);
		modelMap.put("user", user);
		modelMap.put("status", status);
		return "eshop/back/backTradeList";
	}  
	
	
	
	
	/******************************后台店铺列表******************************/
	@RequestMapping("backEshopList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backEshopList(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		backEshopListModelMap(request,response,modelMap);
		return "eshop/back/backEshopList";
	}
	
	
	@RequestMapping("backEshopListMore")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backEshopListMore(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		backEshopListModelMap(request,response,modelMap);
		return "eshop/back/backEshopListMore";
	}

	private ModelMap backEshopListModelMap(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		User user = WebUtil.getCurrentUser(request);

		// 设置分页
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);

		String keyWord = request.getParameter("keyWord");
		if (StringUtil.isNotBlank(keyWord)) {
			try {
				keyWord = URLDecoder.decode(URLDecoder.decode(keyWord, "UTF-8"), "UTF-8");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		}
		Long saleEshopId = HttpUtil.getLongValueFromRequest(request, "saleEshopId");
		Integer qualification = HttpUtil.getIntegerValueFromRequest(request, "qualification");
		Integer taxpayer = HttpUtil.getIntegerValueFromRequest(request, "taxpayer");
		Integer trademark = HttpUtil.getIntegerValueFromRequest(request, "trademark");
		Integer price = HttpUtil.getIntegerValueFromRequest(request, "price");
		Integer industry = HttpUtil.getIntegerValueFromRequest(request, "industry");
		String orderBy = "truth asc";

		SaleEshopQuery saleEshopQuery = new SaleEshopQuery();
		saleEshopQuery.setOnlyKey(onlyKey);
		saleEshopQuery.setSaleEshopId(saleEshopId);
		saleEshopQuery.setKeyWord(keyWord);
		saleEshopQuery.setOrderby(orderBy);
		saleEshopQuery.setQualification(qualification);
		saleEshopQuery.setTaxpayer(taxpayer);
		saleEshopQuery.setTrademark(trademark);
		saleEshopQuery.setPrice(price);
		saleEshopQuery.setIndustry(industry);
		saleEshopQuery.setStatus(0);
		int size = this.saleEshopService.getSaleEshopCountByQuery(saleEshopQuery);
		saleEshopQuery.setPage(page);
		List<SaleEshop> saleEshopList = this.saleEshopService.getSaleEshopListBySaleEshopQuery(saleEshopQuery);
		
		List<SaleEshopVO> saleEshopVOList = new ArrayList<SaleEshopVO>();
		SaleEshopVO saleEshopVO = null;
		if(saleEshopList != null && saleEshopList.size() > 0){
			for(SaleEshop saleEshop : saleEshopList){
				saleEshopVO = new SaleEshopVO();
				Eshop eshop = this.eshopService.getEshopBySaleEshopId(saleEshop.getId());
				/*if(eshop == null || eshop.getTruthSale() == null || eshop.getTruthSale() != 0){
					continue;
				}*/
				saleEshopVO.setEshopCompany(this.eshopCompanyService.getEshopCompanyByEshopCompanyId(saleEshop.getEshopCompanyId()));
				saleEshopVO.setEshopTrademark(this.eshopTrademarkService.getEshopTrademarkByEshopTrademarkId(saleEshop.getTrademarkId()));
				saleEshopVO.setSaleEshop(saleEshop);
				saleEshopVO.setEshop(eshop);
				if(eshop != null){
					saleEshopVO.setEshopUserInfo(this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(eshop.getEshopSellerId()));
				}
				saleEshopVOList.add(saleEshopVO);
			}
		}
		
		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("industry", industry);
		modelMap.put("trademark", trademark);
		modelMap.put("taxpayer", taxpayer);
		modelMap.put("price", price);
		modelMap.put("user", user);
		modelMap.put("qualification", qualification);
		modelMap.put("saleEshopVOList", saleEshopVOList);
		modelMap.put("keyWord", keyWord);
		modelMap.put("orderBy", orderBy);
		return modelMap;
	}
	
	/**
	 * 通过用户发的id搜索店铺
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backEshopById")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backEshopById(HttpServletRequest request,HttpServletResponse response,ModelMap modelMap){
		backEshopListModelMap(request,response,modelMap);
		return "eshop/back/backEshopListMore";
	}
	
	
	/********************************************后台看到的用户提交的各种类型需求************************************************/
	
	/**
	 * 后台xuqiu列表页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("xuqiuList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String xuqiuList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		User user = WebUtil.getCurrentUser(request);
		modelMap.put("user", user);
		return "eshop/back/xuqiuList";
	}
	
	
	/**
	 * 后台列表页
	 * 
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backEshopUserInfoList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backEshopUserInfoList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
		backeshopinfoListModelMap(request, response, modelMap);
		return "eshop/back/backEshopUserInfoList";
	}
	
	public ModelMap backeshopinfoListModelMap(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		User user = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		//0:卖家    1:买家     0:卖家     9:评估     8:代入驻    7:个人需求    
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		
		
		Integer type = HttpUtil.getIntegerValueFromRequest(request, "type");
		if(type == null ){
			return null;
		}
		EshopUserQuery eshopUserQuery = new EshopUserQuery();
		eshopUserQuery.setOnlyKey(onlyKey);
		eshopUserQuery.setType(type);
		int size = this.eshopBizImpl.getEshopUserInfoCountByQuery(eshopUserQuery);
		
		eshopUserQuery.setPage(page);
		List<EshopUserInfo> eshopUserInfoList = this.eshopBizImpl.getEshopUserInfoListByQuery(eshopUserQuery);
		modelMap.put("eshopUserInfoList", eshopUserInfoList);
		
		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("user", user);
		modelMap.put("type", type);
		return modelMap;
	}
	
	/**
	 * 后台修改联系、未联系
	 */
	@RequestMapping("changeBackInfoStatus")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<Boolean> changeBackInfoStatus(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		Long eshopUserInfoId = HttpUtil.getLongValueFromRequest(request, "eshopUserInfoId");
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(eshopUserInfoId);
		eshopUserInfo.setStatus(status);
		if(this.eshopUserInfoService.modifyEshopUserInfoBySellerInfo(eshopUserInfo) == 1){
			responseEntity.setCode("200");
			responseEntity.setData(null);
			responseEntity.setMessage("修改成功");
		}
		return responseEntity;
	}
	/**
	 * 后台修改备注
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backEshopUserInfoRemarkModify")
	@ResponseBody
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public ResponseEntity<Boolean> backEshopUserInfoRemarkModify(HttpServletRequest request, HttpServletResponse response,
			ModelMap modelMap) {
		ResponseEntity<Boolean> responseEntity = new ResponseEntity<>();
		Long eshopUserInfoId = HttpUtil.getLongValueFromRequest(request, "eshopUserInfoId");
		if (eshopUserInfoId == null || eshopUserInfoId <= 0) {
			responseEntity.initErrorResponseEntity(false, "eshopUserInfoId error");
			return responseEntity;
		}
		EshopUserInfo eshopUserInfo = this.eshopUserInfoService.getEshopUserInfoBySellerInfoId(eshopUserInfoId);
		String remarks = request.getParameter("remarks");// 备注
		eshopUserInfo.setRemark(remarks);
		this.eshopUserInfoService.modifyEshopUserInfoBySellerInfo(eshopUserInfo);
		responseEntity.initSuccResponseEntity(true, "succ");
		return responseEntity;
	}
	
	/////////////////////////////////////////////////////主动联系的天猫店铺//////////////////////////////////////////////////////////////
	/**
	 * 运营主动联系天猫店铺
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("eshopTouchList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String eshopTouchList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		eshopTouchListModelMap(request,response,modelMap);
		return "eshop/back/backEshopTouchList";
	}
	
	@RequestMapping("eshopTouchListMore")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String eshopTouchListMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		eshopTouchListModelMap(request,response,modelMap);
		return "eshop/back/backEshopTouchListMore";
	}
	
	public ModelMap eshopTouchListModelMap(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		String keyWord = HttpUtil.getStringValueFromRequest(request, "keyWord");
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		Integer status =HttpUtil.getIntegerValueFromRequest(request, "status");
		User user = WebUtil.getCurrentUser(request);
		
		//设置分页
		Page page = new Page();
		int pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		int pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
			
		EshopTouchQuery eshopTouchQuery = new EshopTouchQuery();
		eshopTouchQuery.setKeyWord(keyWord);
		eshopTouchQuery.setOnlyKey(onlyKey);
		eshopTouchQuery.setStatus(status);
		EshopTouchExample example = this.eshopTouchBizImpl.getEshopTouchExampleByQuery(eshopTouchQuery);
		int size = this.eshopTouchService.getEshopTouchCount(example);
		eshopTouchQuery.setPage(page);
		example = this.eshopTouchBizImpl.getEshopTouchExampleByQuery(eshopTouchQuery);
		List<EshopTouch>  eshopTouchList = this.eshopTouchService.getEshopTouchListByExample(example);
		
		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("eshopTouchList", eshopTouchList);
		modelMap.put("keyWord", keyWord);
		modelMap.put("status", status);
		modelMap.put("user", user);
		return modelMap;
	}
	
	
	
	@RequestMapping("addEshopTouchAction")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	@ResponseBody
	public ResponseEntity<String> addEshopTouchAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		User user = WebUtil.getCurrentUser(request);
		String eshopName = HttpUtil.getStringValueFromRequest(request, "eshopName");
		EshopTouch eshopTouch = new EshopTouch();
		if(StringUtils.isBlank(eshopName)){
			responseEntity.initErrorResponseEntity("-300", "没有填写店铺名");
			return responseEntity;
		}
		eshopTouch.setEshopName(eshopName);
		eshopTouch.setCreateUserId(user.getId());
		eshopTouch.setCommOnlyKey(onlyKey);
		eshopTouch.setEshopType(0);
		eshopTouch.setStatus(0);
		eshopTouch.setGmtCreate(new Date());
		eshopTouch.setGmtModify(new Date());
		String pyName = PinYinUtil.getPinYinFromChinese(eshopName) + eshopName;
		eshopTouch.setPyName(pyName);
		int isInsert = this.eshopTouchService.insertEshopTouch(eshopTouch);
		if(isInsert <= 0){
			responseEntity.initErrorResponseEntity("-200", "操作失败");
			return responseEntity;
		}
		responseEntity.initSuccResponseEntity("200", "操作成功");
		return responseEntity;
	}
	
	/**
	 * 修改店铺联系信息
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("modifyEshopTouchStatus")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	@ResponseBody
	public ResponseEntity<String> modifyEshopTouchStatus(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		ResponseEntity<String> responseEntity = new ResponseEntity<String>();
		Integer status = HttpUtil.getIntegerValueFromRequest(request, "status");
		String remark = HttpUtil.getStringValueFromRequest(request, "remark");
		Long eshopTouchId = HttpUtil.getLongValueFromRequest(request, "eshopTouchId");
		String contactPhone = HttpUtil.getStringValueFromRequest(request, "contactPhone");
		String contactPeople = HttpUtil.getStringValueFromRequest(request, "contactPeople");
		EshopTouch eshopTouch = this.eshopTouchService.getEshopTouchById(eshopTouchId);
		if(status != null){
			eshopTouch.setStatus(status);
		}
		if(StringUtils.isNotBlank(remark)){
			eshopTouch.setRemark(remark);
		}
		if(StringUtils.isNotBlank(contactPeople)){
			eshopTouch.setContactPeople(contactPeople);
		}
		if(StringUtils.isNotBlank(contactPhone)){
			eshopTouch.setContactPhone(contactPhone);
		}
		eshopTouch.setGmtModify(new Date());
		int isModify = this.eshopTouchService.modifyEshopTouch(eshopTouch);
		if(isModify <= 0){
			responseEntity.initErrorResponseEntity("-200", "操作失败");
			return responseEntity;
		}
		responseEntity.initSuccResponseEntity("200", "操作成功");
		return responseEntity;
	}
	
	
	
	/*************************后台查看用户收藏列表*********************************/
	/**
	 * 后台收藏列表页
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backCollectionList")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backCollectionList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		backCollectionModelMap(request, response, modelMap);
		return "eshop/back/backCollectionList";
	}
	
	
	/**
	 * 后台收藏列表页
	 * @param request
	 * @param response
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("backCollectionListMore")
	@EShopUserSecurity(isPc=true)
	@AdminSecurity(userType = UserConstant.TYPE_MANAGE)
	public String backCollectionListMore(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		backCollectionModelMap(request, response, modelMap);
		return "eshop/back/backCollectionListMore";
	}
	
	public ModelMap backCollectionModelMap(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
		User user = WebUtil.getCurrentUser(request);
		Integer onlyKey = HttpUtil.getCommkeyId(request, response);
		
		Page page = new Page();
		Integer pageNo = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageNo", 1);
		Integer pageSize = HttpUtil.getIntegerValueHasDefaultFromRequest(request, "pageSize", PageUtil.PAGE_SIZE);
		page.setPageByPageNoAndPageSize(pageNo, pageSize);
		
		CollectionQuery collectionQuery = new CollectionQuery();
		collectionQuery.setOnlyKey(onlyKey);
		collectionQuery.setType(CollectionEnum.ESHOPTYPE.getCode());
		collectionQuery.setStatus(CollectionEnum.COLLECTION.getCode());
		CollectionExample example = this.collectionBizImpl.getCollectionExampleByQuery(collectionQuery);
		int size = this.collectionService.getCollectionCountByExample(example);
		List<Collection> eshopCollectionList = this.collectionBizImpl.getCollectionByUserIdAndOnlyKey(null, onlyKey, null, page, CollectionEnum.ESHOPTYPE.getCode(), CollectionEnum.COLLECTION.getCode());
		List<CollectionVO> collectionVOList = this.collectionBizImpl.getCollectionVOListByCollectionList(eshopCollectionList);
	
		
		int pageCount = PageUtil.getPageNO(size, PageUtil.PAGE_SIZE);
		modelMap.put("pageCount", pageCount);
		modelMap.put("pageNo", pageNo);
		modelMap.put("collectionVOList", collectionVOList);
		modelMap.put("user", user);
		return modelMap;
	}
	
}
